package com.example.fishdriver.recyclerviewdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

public class IiemDecorationActivity extends AppCompatActivity {
    private RecyclerView mRecyclerView;
    private List<String> list;
    private DefaultLoadMoreView mFootView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_iiem_decoration);
        list=new ArrayList<>();
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        list.add("啥课代表暗示暗示了贷款");
        mRecyclerView= (RecyclerView) findViewById(R.id.rv);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setAdapter(new TestAdapter(this,R.layout.item_de,list));
        mRecyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.HORIZONTAL_LIST));

        findViewById(R.id.bt).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mFootView==null){
                    mFootView=new DefaultLoadMoreView(IiemDecorationActivity.this,mRecyclerView);
                }
                mRecyclerView.removeItemDecoration(mFootView);
                mRecyclerView.addItemDecoration(mFootView);
            }
        });

        findViewById(R.id.remove_bt).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mRecyclerView.removeItemDecoration(mFootView);
            }
        });
    }
}
